package com.shop.config;

import com.shop.interceptor.ShoppingLoginINterceptor;
import com.shop.util.SYS;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ShopWebMVCConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //定义D：//shopupload中的资源的访问路径
        //让Springmvc添加一个处理器，访问静态资源
        registry.addResourceHandler(SYS.FILE_UPLOAD_URL+"/**").addResourceLocations("file:"+SYS.FILE_UPLOAD_DIR);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ShoppingLoginINterceptor()).addPathPatterns("/shopping/contact","/contact/**");

        registry.addInterceptor(new ShoppingLoginINterceptor()).addPathPatterns("/shopping/cart","/cart/**");

        registry.addInterceptor(new ShoppingLoginINterceptor()).addPathPatterns("/shopping/checkout","/checckout/**");

        registry.addInterceptor(new ShoppingLoginINterceptor()).addPathPatterns("/shopping/userinfo","/userinfo/**");
    }
}
